/*
 * @Author: your name
 * @Date: 2022-04-03 16:59:51
 * @LastEditTime: 2022-04-13 14:40:45
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \drivingTow\src\trainees\trainees.controller.ts
 */
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Req } from '@nestjs/common';
import { TraineesService } from './trainees.service';
import { CreateTraineeDto } from './dto/create-trainee.dto';
import { Create_timeDto, SelectTraineeDto, UpdateTraineeDto } from './dto/update-trainee.dto';
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { RolesGuard } from 'src/auth/role.guard';
import { selectAllPraticeDto } from 'src/practice/dto/update-practice.dto';

@ApiTags('学员练车记录表')
@Controller('trainees')
export class TraineesController {
  constructor(private readonly traineesService: TraineesService) {}
  @ApiOperation({ summary: '创建学员练车记录' })
  @ApiBearerAuth()
  @Post('getTrainee')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getTrainee(@Body() post:CreateTraineeDto,@Req() req){
    return await this.traineesService.createTrainee(post,req.user)
  }

  @ApiOperation({ summary: '获取学员用户练车记录' })
  @ApiBearerAuth()
  @Post('getTraineeById')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getTraineeById(@Body() post:SelectTraineeDto,@Req() req){
    const newPost = {
      ...post,
      id:req.user.id
    }
    return await this.traineesService.findById(newPost)
  }

  @ApiOperation({ summary: '获取学员今日预约状态' })
  @ApiBearerAuth()
  @Post('findByIdStatus')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async findByIdStatus(@Body() post:Create_timeDto,@Req() req){
    const newPost = {
      ...post,
      id:req.user.id
    }
    return await this.traineesService.findByIdStatus(newPost)
  }

  @ApiOperation({ summary: '修改当前状态' })
  @ApiBearerAuth()
  @ApiParam({name:'id',description:'id'})
  @Get('updataStatus:id')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async updataStatus(@Param('id') id){
    return this.traineesService.updataStatus(id)
  }

  @ApiOperation({ summary: '取消当前状态' })
  @ApiBearerAuth()
  @ApiParam({name:'id',description:'id'})
  @Get('cancelStatus:id')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async cancelStatus(@Param('id') id){
    return this.traineesService.cancelStatus(id)
  }

  @ApiOperation({ summary: '删除该练车记录' })
  @ApiBearerAuth()
  @ApiParam({name:'id',description:'id'})
  @Get('deleteTrainee:id')
  @UseGuards(AuthGuard('jwt'), RolesGuard)  
  async deleteTrainee(@Param('id') id){
    return this.traineesService.deleteTrainee(id)
  }

  @ApiOperation({ summary: '管理员查看所有的练车记录' })
  @ApiBearerAuth()
  @Post('getAllTrainee')
  @UseGuards(AuthGuard('jwt'), RolesGuard)
  async getAllTrainee(@Body() post:selectAllPraticeDto){
    return this.traineesService.getAllTrainee(post)
  }
}
